package com.batch_demo.jdk8;

import java.util.Optional;

public class OptionalDemo {
    public void m1() {
        Optional<String> fullName = Optional.ofNullable(null);
        System.out.println("Full Name is set ? " + fullName.isPresent());
        System.out.println("Full Name: " + fullName.orElseGet(() -> "[none]"));
        System.out.println(fullName.map(s -> "Hey " + s + "!" ).orElse("Hey Stranger!"));
    }

    public void m2() {
        Optional<String> firstName = Optional.of("Tom");
        System.out.println("First Name is set ?" + firstName.isPresent());
        System.out.println("First Name : " + firstName.orElseGet(() -> "[none]"));
        System.out.println(firstName.map(s -> "Hey " + s + '!').orElse("Hey Stranger"));
    }

    public static void main(String[] args) {
        OptionalDemo optionalDemo = new OptionalDemo();
        optionalDemo.m1();
        optionalDemo.m2();
    }
}
